<template>
  <img ref="img_" />
</template>
<script>
import { downFileByFileNo } from '@/services/common'
export default {
  name: 'AuthImg',
  props: {
    fileNo: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {

    }
  },
  watch: {
    fileNo(val) {
      if (!val) {
        this.$refs.img_.src = ''
        return
      }
      this.getSrc()
    }
  },
  methods: {
    getSrc() {
      const img = this.$refs.img_
      downFileByFileNo(this.fileNo).then(data => {
        img.src = URL.createObjectURL(data) // 根据文件获取图片url
        img.onload = () => {
          URL.revokeObjectURL(img.src)
        }
      })
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.getSrc()
    })
  }
}
</script>
